package com.exsun.gateway.jt809.start;

import com.exsun.gateway.jt809.config.NettyClientConfig;
import com.exsun.gateway.jt809.master.JT809Client;
import org.apache.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class MasterRunner implements CommandLineRunner {
    private final static Logger logger = Logger.getLogger(MasterRunner.class);
    @Autowired
    private JT809Client jt809Client;
    @Autowired
    private NettyClientConfig nettyClientConfig;
    @Override
    public void run(String... args) throws Exception {
        logger.info("-----Connect start-----");
        try {
            logger.info("连接上级平台: " + nettyClientConfig.getSuperiorIp()+":"+nettyClientConfig.getSuperiorPort());
            jt809Client.connect(nettyClientConfig.getSuperiorIp(), nettyClientConfig.getSuperiorPort());// 启动tcp客户端连接
        } catch (Exception e) {
            logger.error("-----Connect Error-----");
            e.printStackTrace();
        }
    }


}